package com.bnzj.cloud.auth.controller;

import com.bnzj.core.rest.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Tag(name = "用户退出")
@RestController
public class LogoutController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Operation(summary = "退出登录", description = "退出登录")
    @GetMapping("/user/logout")
    public ResponseResult<?> logout(HttpServletRequest request) {
        try {
            String header = request.getHeader("token");
            String[] tokens = header.split(",");
            String token1 = tokens[0];
            stringRedisTemplate.delete("SYSGN_TOKEN:" + token1);
        } catch(Exception e) {
            return ResponseResult.failure(0, "退出失败");
        }
        return ResponseResult.success();
    }

}
